package com.wzcl.app.utils;


import org.apache.commons.lang3.StringUtils;

/**
 * @Author Silen
 * @Since 2019/11/19 17:35
 * 自定义生成订单号规则：
 *  两位随机大写字母+用户手机尾号4位+当前时间毫秒数
 */
public class OrderNoUtil {

    public static StringBuffer generateOrderNo(String uphone) throws Exception {
        /*电话号码判空*/
        if(!StringUtils.isNotBlank(uphone)){
            return null;
        }
        /*构建订单号初始空Stringbuffer*/
        StringBuffer orderNo = new StringBuffer();

        /*电话尾号4位*/
        StringBuffer  phoneCode = new StringBuffer(uphone).delete(0,7);

        /*拼接电话尾号*/
        orderNo.append(phoneCode);

        /*获取当前系统时间毫秒数*/
        long currentTime = System.currentTimeMillis();
        /*当前时间毫秒数截取*/
        StringBuffer currentTimeCode = new StringBuffer(Long.toString(currentTime)).delete(0,2);

        /*拼接当前时间毫秒数*/
        orderNo.append(currentTimeCode);

        return orderNo;
    }
}
